<!--空白弹出页面参考模版-->
{extend name='public/layer_base' /}
{block name='content'}
<!-- 这里写内容即可 -->
<div class="row">
    <div class="col-md-12">
        <!--数据列表顶部-->
        <div class="box-header">
            <div>
                <div class="box-body">
                    <div class="col-md-12">
                        <div class="box box-primary">
                            <!-- 表单 -->
                            <form  class="form-horizontal dataForm">
                                <!-- 表单字段区域 -->
                                <div class="box-body">
                                    <div class="form-group">
                                        <label for="me_uid" class="col-sm-2 control-label">用户融云ID</label>
                                        <div class="col-sm-10 col-md-4">
                                            <input id="me_uid" value="{$memberinfo.member_id|default=''}"
                                                   readonly type="text" class="form-control field-text">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="me_nick_name" class="col-sm-2 control-label">用户昵称</label>
                                        <div class="col-sm-10 col-md-4">
                                            <input id="me_nick_name" value="{$memberinfo.me_nick_name|default=''}"
                                                   readonly type="text" class="form-control field-text">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label for="chi_id" class="col-sm-2 control-label">流量池推送选择</label>
                                        <div class="col-sm-10 col-md-4">
                                            <select name="chi_id" id="chi_id" class="form-control field-select" data-placeholder="请选择流量池">
                                                {foreach $list as $key=>$value}
                                                <option value="{$value.id}">{$value.chi_name}（单日{$value.push_num}推送）</option>
                                                {/foreach}
                                                <option value="-99">【关闭流量池推送】</option>
                                            </select>
                                        </div>
                                    </div>


                                    <input name="member_id" id="member_id" type="hidden" value="{$member_id}">


                                    <div class="form-group">
                                        <label for="disable" class="col-sm-2 control-label"></label>
                                        <div class="col-sm-10 col-md-4" style="text-align: center;">
                                            <a class="btn btn-success btn-sm ktAjaxButton" data-toggle="tooltip" title=""
                                               data-confirm-title="是否确认" data-confirm-content="确认此编辑？"
                                               data-id="checked"
                                               data-url="{:url('actionsetchi')}">
                                                确认编辑
                                            </a>
                                        </div>
                                    </div>



                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        //弹框内确认  禁用回车键
        $(document).on('keydown keypress', function(event) {
            if (event.keyCode == 13) {
                event.preventDefault();
            }
        });


        $('body').on('click', '.ktAjaxButton', function (event) {
            console.log("ktAjax")
            event.preventDefault();

            if (adminDebug) {
                console.log('AjaxButton clicked.');
            }
            //是否弹出提示
            let layerConfirm = $(this).data("confirm") || 1;
            //访问方式，1为直接访问，2为layer窗口显示
            let layerType = parseInt($(this).data("type") || 1);
            //访问的url
            let url = $(this).data("url");
            //访问方式，默认post
            let layerMethod = $(this).data("method") || 'post';
            //访问成功后跳转的页面，不设置此参数默认根据后台返回的url跳转
            let go = $(this).data("go") || 'url://reload';
            // let go = 'url://close-refresh';

            //当为窗口显示时可定义宽度和高度
            let layerWith = $(this).data("width") || '30%';
            let layerHeight = $(this).data("height") || '30%';

            //窗口的标题
            let layerTitle = $(this).data('title');

            //当前操作数据的ID
            let dataId = $(this).data("id");

            let dataData;

            //如果没有定义ID去查询data-data属性
            if (dataId === undefined) {
                dataData = $(this).data("data") || {};
            } else {
                dataData = {
                    "member_id": $("#member_id").val(),
                    "chi_id": $("#chi_id").val(),
                };
            }

            if (typeof (dataData) != 'object') {
                dataData = JSON.parse(dataData);
            }

            /*需要确认操作*/
            if (parseInt(layerConfirm) === 1) {
                //提示窗口的标题
                let confirmTitle = $(this).data("confirmTitle") || '操作确认';
                //提示窗口的内容
                let confirmContent = $(this).data("confirmContent") || '您确定要执行此操作吗?';
                layer.confirm(confirmContent, {title: confirmTitle, closeBtn: 1, icon: 3}, function () {
                    //如果为直接访问
                    if (layerType === 1) {
                        ajaxRequests(url, layerMethod, dataData, go);
                    } else if (layerType === 2) {
                        //如果为打开窗口
                        //先进行权限查询
                        if (checkAuth(url)) {
                            layer.open({
                                type: 1,
                                area: [layerWith, layerHeight],
                                title: layerTitle,
                                closeBtn: 1,
                                shift: 0,
                                content: url + "?request_type=layer_open&" + parseParam(dataData),
                                scrollbar: false,
                            });
                        }
                    }
                });
            } else {
                //不需要操作确认
                if (layerType === 1) {
                    //直接请求
                    ajaxRequests(url, layerMethod, dataData, go);
                } else if (layerType === 2) {
                    //弹出窗口
                    //检查权限
                    if (checkAuth(url)) {
                        //用窗口打开
                        layer.open({
                            type: 2,
                            area: [layerWith, layerHeight],
                            title: layerTitle,
                            closeBtn: 1,
                            shift: 0,
                            content: url + "?request_type=layer_open&" + parseParam(dataData),
                            scrollbar: false,
                        });
                    }
                }
            }
        });

        function ajaxRequests(url, method, data, go) {
            let loadT = layer.msg('正在请求,请稍候…', {icon: 16, time: 0, shade: [0.3, '#000'], scrollbar: false,});
            $.ajax({
                    url: url,
                    dataType: 'json',
                    type: method,
                    data: data,
                    success: function (result) {
                        // debugger
                        layer.close(loadT);
                        layer.msg(result.msg, {
                            icon: result.code ? 1 : 2,
                            scrollbar: false,
                        });

                        if (adminDebug) {
                            console.log('request success!');
                            if (result.code === 1) {
                                console.log('%cresult success', ';color:#00a65a');
                                go = 'url://close-refresh';
                            } else {
                                console.log('%cresult fail', ';color:#f39c12');
                                go = 'url://reload';
                            }
                            setTimeout(function () {
                                goUrl(go);
                            }, 2000);
                        }
                        // setTimeout("alert('123')", 3000 )

                    },
                    error: function (xhr, type, errorThrown) {
                        console.log("error")
                        //异常处理；
                        if (adminDebug) {
                            console.log('%crequest fail!', ';color:#dd4b39');
                            console.log();
                            console.log("type:" + type + ",readyState:" + xhr.readyState + ",status:" + xhr.status);
                            console.log("url:" + url);
                            console.log("data:");
                            console.log(data);
                            layer.close(loadT);
                        }
                        layer.msg('访问错误,代码' + xhr.status, {icon: 2, scrollbar: false,});
                    }
                }
            );
        }
    </script>

    {/block}